#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <netdb.h>

int
main(int argc, char** argv)
{
    if (argc < 2)
    {
        puts("host name required");
        exit(-1);
    }

    // search domin ip of uestc.edu.cn
    struct hostent *hptr = NULL;
    for (int i = 1 ; i < argc ; i++)
    {
        if ((hptr = gethostbyname(argv[i])) != NULL) {
            printf("official host name for %s:\n%s\n", argv[i], hptr->h_name);
            printf("ip address(es) for %s:\n", hptr->h_name);
            for (int i = 0 ; hptr->h_addr_list[i] != NULL ; i++){
                printf("%s\n", inet_ntoa(*(struct in_addr *)(hptr->h_addr_list[i])));
            }
        }
        else{
            printf("not found ip for %s\n", argv[i]);
        }

        printf("\n");

    }
    
    return 0;
}
